package makovo.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import makovo.data.Resources;
import makovo.entities.ApplicantWithDocs;
import makovo.entities.Project;
import makovo.entities.SocInfo;

import org.apache.struts2.interceptor.SessionAware;
import org.json.JSONObject;

import com.google.gson.Gson;

public class ApplicantInfo extends HttpServlet implements SessionAware {
	private static final long serialVersionUID = 1L;
	private String mCurp;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			HttpSession session = request.getSession();
			// session.setAttribute("User.idSender", "RICR860323VMMHDF08");
			mCurp = (String) session.getAttribute("User.idSender");

			// mCurp = "RICR860323VMMHDF08";

			request.setCharacterEncoding("utf8");
			// response.setCharacterEncoding("utf8");
			response.setContentType("application/json");

			ApplicantWithDocs applicantInfo = Resources.getApplicantWithDocs(mCurp);
			SocInfo socInfo = Resources.getSocInfoByCURP(mCurp);
			Project project = Resources.getProjectInfoByCURP(mCurp);

			Gson gson = new Gson();

			response.getWriter().write("{\"a\":");
			response.getWriter().write(applicantInfo == null ? "null" : gson.toJson(applicantInfo));
			response.getWriter().write(",\"s\":");
			response.getWriter().write(socInfo == null ? "null" : gson.toJson(socInfo));
			response.getWriter().write(",\"p\":");
			response.getWriter().write(project == null ? "null" : gson.toJson(project));
			response.getWriter().write("}");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void setSession(Map<String, Object> arg0) {

	}

}
